<html>

<head>
	<link rel="stylesheet" type="text/css" href="css/swiper-3.4.2.min.css" />
	<style type="text/css">
		* {
			margin: 0;
			padding: 0
		}

		.swiper-container {
			width: 960px;
			height: 398px;
			margin-left: 0;
		}

		a {
			width: 960px;
			height: 398px;
			display: inline-block;
		}

		a img {
			width: 960px;
			height: 398px;
		}

		.swiper-pagination-bullet {
			background: #fff;
			opacity: 0.6;
			width: 10px;
			height: 10px;
		}

		.swiper-pagination-bullet-active {
			background: #FFAA40;
			opacity: 1;
			width: 10px;
			height: 10px;
		}

		.swiper-pagination {
			text-align: left;
			text-indent: 300px;
		}
	</style>
</head>

<body>
	<!--把下面代码加到body与body之间-->
	<div class="swiper-container">
		<div id="loginSwiper" class="swiper-wrapper">
			<!--<div class="swiper-slide"><a href="http://rzds.glodonedu.com/rzds/news/bulletin/publicity"><img src="img/login.jpg"/></a></div>-->
			<!--<div class="swiper-slide"><a href="http://kaoshi.glodonedu.com/login"><img src="img/login_ad2.png"/></a></div>
			<div class="swiper-slide"><a href="javascript:void(0);"><img src="img/login_ad4.jpg"/></a></div>
			<div class="swiper-slide"><a href="javascript:void(0);"><img src="img/login_ad5.jpg"/></a></div>-->
		</div>
		<!-- 如果需要分页器 -->
		<!-- <div class="swiper-pagination"></div> -->
	</div>
</body>

</html>
<script src="js/jquery-2.1.4.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/swiper-3.4.2.min.js" type="text/javascript" charset="utf-8"></script>
<script>
	var loginSwiper = $('#loginSwiper')

	$.ajax({
		type: 'POST',
		url: 'http://kaoshi.glodonedu.com/restApi/rzds/getBanner',
		data: {
			code: 'bwrcpcLogin'
		}
	}).success(function (result) {
		if (result.success && result.data && result.data.length) {
			result.data.forEach(function (item) {
				loginSwiper.append("<div class='swiper-slide'><a href='" + item.bannerLink + "'><img src='" + item.bannerPhoto + "' /></a></div>")
			});
		} else {
			addDefaultImg()
		}
		createSwiper()
	}).error(function (error) {
		console.log(error);
		addDefaultImg()
		createSwiper()
	})

	function addDefaultImg() {
		loginSwiper.append("<div class='swiper-slide'><a href='https://dx5.cn/YbrV30'><img src='img/login3.jpg' /></a></div>")
	}

	// 初始化轮播
	function createSwiper(params) {
		var mySwiper = new Swiper('.swiper-container', {
			autoplay: 5000,//可选选项，自动滑动
			direction: 'horizontal',
			loop: true,
			// 如果需要分页器
			// pagination: '.swiper-pagination',
			// paginationClickable: true,
			autoplayDisableOnInteraction: false,
		})
	}
</script>